<?php
/**
 * Created by allen.qiang
 * Date: 14-12-22
 * Time: 下午2:37
 * BD圣诞节活动
 * FUN-AC-0031
 */
quanli_require('module/func/eai.func.php');
quanli_require('module/base/activity/activitySpike.class.php');
quanli_require('module/base/activity/activityConfig.class.php');//活动配置文件
quanli_include('module/base/promotion/quanliCoupon.class.php');//加载优惠券类



class ajax_christmas{


    public function execute() {

        if (isset($_REQUEST['operFlg']) && $_REQUEST['operFlg'] > 0) {

            switch($_REQUEST['operFlg']) {

                case 1://用户选择的蛋糕信息
                    $this->check();
                    break;
                case 2://选择礼包信息
                    $this->selected();
                    break;
            }

        } else {

            $this->toReturn('参数错误');

        }

    }
    //选择蛋糕信息
    function check(){

        global $G_SHOP;
        if(!$G_SHOP->currentPCustID){
            returnJsonData("未登录", 400);
        }
        $activity_config = new activityConfig('christmas_cake'); //活动配置
        $config_array = $activity_config->config;
        $postID=$_REQUEST['postID'];//所选蛋糕网购号
        $postIDArray=explode(",",$config_array['postID']);//活动蛋糕网购号数组
        if(in_array($postID,$postIDArray)){
            returnJsonData($postID, 200);
        }else{
            returnJsonData("蛋糕信息错误！", 400);
        }


        returnJsonData('111', 200);
    }
    //选择礼包信息
    function selected(){

        global $G_SHOP;
        if(!$G_SHOP->currentPCustID){
            returnJsonData("未登录", 400);
        }
        $checkArray=array(1,2,3);
        if(in_array($_REQUEST['ckeckid'],$checkArray)){
            $activity_config = new activityConfig('christmas_cake'); //活动配置
            $config_array = $activity_config->config;
            //当天开始日期
            $beginTime=date('Y-m-d').' 00:00:00';
            //当天结束日期
            $endTime=date('Y-m-d').' 23:59:59';

            $activitySql="select count(1) as num3  from activities_extend where activityNumber= ? and  createTime > ? and  createTime < ? ";
            $activity=$G_SHOP->DBCA->stmt_query($activitySql,'sss',66000,$beginTime,$endTime);
            if($activity[0]->num3<$config_array['number']){

                $activitySql="select extend_7  from activities_extend where extend_1= ? and activityNumber= ? and  createTime > ? and  createTime < ? ";
                $activitie_query=$G_SHOP->DBCA->stmt_query($activitySql,'ssss',$G_SHOP->currentPCustID,66000,$beginTime,$endTime);
                $usrNum=0;
                $num=0;
                if(!empty($activitie_query)){

                    foreach($activitie_query as $activitie){
                        if($activitie->extend_7!=0){
                            $usrNum=1;
                        }
                    }
                    if($usrNum==1){
                        returnJsonData($_REQUEST['ckeckid'], 400);
                    }else{
                        $updSql=" update activities_extend SET extend_7= ? where extend_1= ? and  activityNumber=? and createTime > ? and  createTime < ?";
                        $activitie_query=$G_SHOP->DBCA->stmt_query($updSql,'sssss',$_REQUEST['ckeckid'],$G_SHOP->currentPCustID,66000,$beginTime,$endTime);
                        returnJsonData($_REQUEST['ckeckid'], 200);
                    }

                }else{
                    returnJsonData($_REQUEST['ckeckid'], 400);
                }
            }else{
                returnJsonData($_REQUEST['ckeckid'], 400);
            }

        }else{
            returnJsonData($_REQUEST['ckeckid'], 400);
        }


    }

}